﻿/*
 * Copyright (c) Jason Paul Morley, 2010
 * Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Algorithms.Steps
{
    public class AssignNode : Core.IStep
    {
        public AssignNode(Core.Node a, double newDistance)
        {
            node1 = a;
            distance = newDistance;
        }

        private double oldDistance;
        private Core.State oldState;
        public void Apply()
        {
            oldDistance = node1.distance;
            node1.distance = distance;

            oldState = node1.state;
            node1.state = Core.State.FurtherHighlighted;
        }

        public void Undo()
        {
            node1.distance = oldDistance;
            node1.state = oldState;
        }

        public string Name()
        {
            return "Assign: " + node1.id + " = " + distance.ToString();
        }

        public Core.Node node1;
        public double distance;

        public void ToNext()
        {
            node1.state = oldState;
        }
    }
}
